<template>
  <div class="container">
    <el-input
        type="textarea"
        class="textarea left custom-input"
        :row="row"
        v-model="leftText"
    />
    <el-input
        type="textarea"
        class="textarea right custom-input"
        :row="row"
        v-model="rightText"
    />
  </div>
  <el-footer>
    <el-button @click="columnToIn" type="primary">
      转换
    </el-button>
    <el-button @click="addBracket" type="primary">
      添加括号
    </el-button>
    <el-button @click="copy" type="primary">
      复制
    </el-button>
  </el-footer>
</template>
<script>
import {leftTextToStrArr, delLastComma, copy2Clipboard} from "../../utils/util.js";

export default {
  name: 'ColToIn',
  data() {
    return {
      row: 10,
      leftText: '',
      rightText: '',
      separator: ','
    }
  },
  methods: {
    columnToIn() {
      const strArr = leftTextToStrArr(this)
      let resultStr = ''
      for (let item of strArr) {
        resultStr += `'${item}',\n`
      }
      this.rightText = delLastComma(resultStr)
    },
    addBracket() {
      if (!this.rightText.startsWith('(')) {
        this.rightText = `(${this.rightText}`
      }
      if (!this.rightText.endsWith(')')) {
        this.rightText = `${this.rightText})`
      }
    },
    copy() {
      copy2Clipboard(this)
    }
  }
}
</script>
<style>

</style>
